package cn.yhp.gateway.session;

import cn.yhp.gateway.session.handlers.SessionServerHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.*;

/**管道初始化
 * @author yhp
 * @description
 * @date 2024/5/6
 */
public class SessionChannelInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ChannelPipeline pipeline = socketChannel.pipeline();
        // 入站请求解码
        pipeline.addLast(new HttpRequestDecoder());
        // 出站请求编码
        pipeline.addLast(new HttpResponseEncoder());
        // 用于处理除了 GET 请求外的 POST 请求时候的对象信息
        pipeline.addLast(new HttpObjectAggregator(1024 * 1024));
        // 自定义处理器 业务逻辑处理
        pipeline.addLast(new SessionServerHandler());
    }
}
